package com.canopys.study.open.test.designpatterns.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Canopys
 * @Descrption:
 * @Date: Created in 21:36 2019/11/7
 * @Modified By:
 */
public class ConcreteSubject implements Subject {

    private final static List<Observer> OBSERVER_LIST = new ArrayList<>();

    private String state;

    @Override
    public void register(Observer observer) {
        OBSERVER_LIST.add(observer);
    }

    @Override
    public void remove(Observer observer) {
        OBSERVER_LIST.remove(observer);
    }

    @Override
    public void notify(String state) {
        OBSERVER_LIST.forEach(e -> e.update(state));
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getState() {
        return this.state;
    }
}
